# -*- coding:utf-8 -*-
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin
# Create your models here.


ProjectStatic = (
    ('Open', u'启用'),
    ('Close', u'关闭'),
)


CaseStatic = (
    ('PASS', u'成功'),
    ('Failed', u'失败'),
)


OfficeList = (
    ('ProjectManager', u'项目经理'),
    ('TestEngineer', u'测试工程师'),
    ('ProjectAdmin', u'项目管理员'),
)


class User(models.Model):
    Username = models.CharField(max_length=50, db_index=True, verbose_name='用户名')
    Password = models.CharField(max_length=50, verbose_name='密码')
    Fullname = models.CharField(max_length=50, verbose_name='全名')
    OfficeName = models.CharField(max_length=40, choices=OfficeList, verbose_name='职位')
    # Email = models.EmailField(verbose_name='邮箱')

    def __unicode__(self):
        return self.Username


class UserAdmin(admin.ModelAdmin):
    list_display = ('Username', )


class Project(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=200)
    description = models.TextField()
    status = models.CharField(max_length=10, choices=ProjectStatic)
    created_user = models.ForeignKey(User)
    created_time = models.DateTimeField(help_text=_('created date'), auto_now_add=True)
    updated_time = models.DateTimeField(help_text=_('updated date'), auto_now=True)

    def __unicode__(self):
        return self.name


class Suite(models.Model):
    id = models.AutoField(primary_key=True)
    project = models.ForeignKey(Project)
    name = models.CharField(max_length=200)
    description = models.TextField()
    suiteSetup = models.CharField(max_length=200)
    suiteTeardown = models.CharField(max_length=200)
    testSetup = models.CharField(max_length=200)
    testTemplate = models.CharField(max_length=200)
    testTimeout = models.CharField(max_length=200)

    def __unicode__(self):
        return self.name


class Library(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=200)
    description = models.TextField(max_length=200)
    # ProjectID = Project.id
    suite = models.ForeignKey(Suite)

    def __unicode__(self):
        return self.name


class Resource(models.Model):
    name = models.CharField(max_length=200)
    description = models.TextField()
    suite = models.ForeignKey(Suite)

    def __unicode__(self):
        return self.name


class Scalar(models.Model):
    name = models.CharField(max_length=200)
    value = models.TextField(max_length=200)
    comment = models.TextField()
    suite = models.ForeignKey(Suite)

    def __unicode__(self):
        return self.name, self.value


class ListVariable(models.Model):
    name = models.CharField(max_length=200)
    value = models.TextField()
    comment = models.TextField()
    suite = models.ForeignKey(Suite)

    def __unicode__(self):
        return self.name, self.value


class Case(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=200)
    description = models.TextField()
    setup = models.CharField(max_length=200)
    teardown = models.CharField(max_length=200)
    timeout = models.CharField(max_length=200)
    template = models.CharField(max_length=200)
    suite = models.ForeignKey(Suite)

    def __unicode__(self):
        return self.name


class CaseDetails(models.Model):
    id = models.AutoField(primary_key=True)
    detail = models.TextField()
    created_user = models.ForeignKey(User)
    created_time = models.DateTimeField(help_text=_('created date'), auto_now_add=True)
    updated_time = models.DateTimeField(help_text=_('updated date'), auto_now=True)
    case = models.ForeignKey(Case)

    def __unicode__(self):
        return self.Detail


class Report(models.Model):
    id = models.AutoField(primary_key=True)
    case = models.ForeignKey(Case)
    content = models.TextField()
    detail = models.TextField()
    error = models.TextField()
    created_user = models.ForeignKey(User)
    created_time = models.DateTimeField(help_text=_('created date'), auto_now_add=True)

    def __unicode__(self):
        return self.content


class ReportDetail(models.Model):
    id = models.AutoField(primary_key=True)
    ReportID = models.ForeignKey(Report)
    detail = models.TextField()
    static = models.CharField(max_length=2, choices=CaseStatic)

    def __unicode__(self):
        return self.detail, self.static

